from our_game_runner import GameRunner
from loa_game import LinesOfActionState, WHITE, BLACK
       
def runMatch(agent1, agent2, gameSize, numOfTurns, turnTime, setupTime):
    state = LinesOfActionState(gameSize, numOfTurns)
    results = [GameRunner(state, {WHITE:agent1, BLACK:agent2}, turnTime, setupTime).run(),
              GameRunner(state, {WHITE:agent2, BLACK:agent1}, turnTime, setupTime).run()]
    retVal = []
    i = 0
    for result in results:
        if result[1] == 3:
            if (i == 0 and result[0] == "W") or (i == 1 and result[0] == "B"):
                retVal += [3, 0]
            else:
                retVal += [0, 3]
        elif result[1] == 1:
            retVal += [1, 1]
        elif result[1] == -2:
            if (i == 0 and result[0] == "W") or (i == 1 and result[0] == "B"):
                retVal += [-2, 2]
            else:
                retVal += [2, -2]
        i += 1
    return tuple(retVal)
    
def Op(player):
    if str(player) == "W": return "B"
    if str(player) == "B": return "W"